#include "Mail System.h"

MailSystem* MailSystem::GetInstance()
{
	static MailSystem instance;
	return &instance;
}
void MailSystem::InitMessageSystem(MESSAGEPROC pfnMsgSys)
{
	if (!pfnMsgSys)	return;
	m_pfnMsgSys = pfnMsgSys;
}

void MailSystem::SendMail(CMessage* pMsg)
{
	if (!pMsg)	return;
	m_MsgQueue.push(pMsg);
}
void MailSystem::ReadMail()
{
	if(!m_pfnMsgSys)	return;
	while(!m_MsgQueue.empty())
	{
		m_pfnMsgSys(m_MsgQueue.front());		
		delete m_MsgQueue.front();				
		m_MsgQueue.pop();						
	}
}
void MailSystem::ClearMessages()
{
	while(!m_MsgQueue.empty())
	{
		delete m_MsgQueue.front();
		m_MsgQueue.pop();
	}
}
void MailSystem::ShutdownMailSystem()
{
	ClearMessages();
	m_pfnMsgSys = NULL;
}